import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import confirm, { ConfirmResult } from '@dfeidao/atom-web/msgbox/confirm';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import refresh from '@dfeidao/atom-web/url/refresh';

export default async function a005(fd: IFeidaoAiBrowserComponent) {
	// 删除方法
	const chklist = fd.data.node.querySelectorAll('[data-id="chklist"]:checked');
	console.log(chklist);
	if (chklist.length === 0) {
		alert('请至少勾选一行要删除的数据！');
		//提示信息两秒后自动消失
		return;
	} else {
		const list = Array.from(chklist) as HTMLInputElement[];
		const arr = list.map((n) => {
			return n.getAttribute('data-no');
		});
		const nos = arr as string[];
		console.log('arrarr', nos);


		const flag = await confirm('确定删除吗', '删除', '确定', '取消', 'red');
		switch (flag) {
			case ConfirmResult.YES:
				const res = await nodejs<{ code: 0 | 1; result: string }>('company-factory/zj-000004/s002', {
					filter: {
						company_nos: nos
					}
				});

				if (res.code === 1) {
					alert('删除成功！');
					refresh();
				} else {
					alert('删除失败！');
				}
				// todo
				break;
			case 'no':
				// todo
				break;
			default:    // cancel
				// todo
				break;
		}

	}


}
